<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Send a CTRL event to another process</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.sapi-windows-cp-set.html">« sapi_windows_cp_set</a></li>
      <li style="float: right;"><a href="function.sapi-windows-set-ctrl-handler.html">sapi_windows_set_ctrl_handler »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.misc.html">杂项 函数</a></li>
    <li>Send a CTRL event to another process</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.sapi-windows-generate-ctrl-event" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">sapi_windows_generate_ctrl_event</h1>
  <p class="verinfo">(PHP 7 &gt;= 7.4.0, PHP 8)</p><p class="refpurpose"><span class="refname">sapi_windows_generate_ctrl_event</span> &mdash; <span class="dc-title">Send a CTRL event to another process</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-function.sapi-windows-generate-ctrl-event-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>sapi_windows_generate_ctrl_event</strong></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$event</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$pid</code><span class="initializer"> = 0</span></span>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   Sends a CTRL event to another process in the same process group.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.sapi-windows-generate-ctrl-event-parameters">
  <h3 class="title">参数</h3>
  <dl>
   
    <dt>
<code class="parameter">event</code></dt>

    <dd>

     <p class="para">
      The <code class="literal">CTRL</code> even to send;
      either <strong><code>PHP_WINDOWS_EVENT_CTRL_C</code></strong>
      or <strong><code>PHP_WINDOWS_EVENT_CTRL_BREAK</code></strong>.
     </p>
    </dd>

   
   
    <dt>
<code class="parameter">pid</code></dt>

    <dd>

     <p class="para">
      The ID of the process to which to send the event to. If <code class="literal">0</code>
      is given, the event is sent to all processes of the process group.
     </p>
    </dd>

   
  </dl>

 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.sapi-windows-generate-ctrl-event-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.sapi-windows-generate-ctrl-event-examples">
  <h3 class="title">范例</h3>
  <div class="example" id="sapi-windows-generate-ctrl-event.example.basic">
   <p><strong>示例 #1 Basic <span class="function"><strong>sapi_windows_generate_ctrl_event()</strong></span> Usage</strong></p>
   <div class="example-contents"><p>
     This example shows how to pass along <code class="literal">CTRL+BREAK</code> events to a child
     process. In this case the child process echoes <code class="literal">I&#039;m still alive</code>
     every second, until the user presses <code class="literal">CTRL+BREAK</code>, what causes
     only the child process to be terminated.
   </p></div>
   <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;forward&nbsp;CTRL+BREAK&nbsp;events&nbsp;to&nbsp;the&nbsp;child&nbsp;process<br /></span><span style="color: #0000BB">sapi_windows_set_ctrl_handler</span><span style="color: #007700">(</span><span style="color: #DD0000">'sapi_windows_generate_ctrl_event'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;create&nbsp;a&nbsp;child&nbsp;process&nbsp;which&nbsp;echoes&nbsp;every&nbsp;second<br /></span><span style="color: #0000BB">$cmd&nbsp;</span><span style="color: #007700">=&nbsp;[</span><span style="color: #DD0000">'php'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'-r'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'while&nbsp;(true)&nbsp;{&nbsp;echo&nbsp;"I\'m&nbsp;still&nbsp;alive\n";&nbsp;sleep(1);&nbsp;}'</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">$descspec&nbsp;</span><span style="color: #007700">=&nbsp;array([</span><span style="color: #DD0000">'pipe'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'r'</span><span style="color: #007700">],&nbsp;[</span><span style="color: #DD0000">'pipe'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'w'</span><span style="color: #007700">],&nbsp;[</span><span style="color: #DD0000">'pipe'</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">'w'</span><span style="color: #007700">]);<br /></span><span style="color: #0000BB">$options&nbsp;</span><span style="color: #007700">=&nbsp;[</span><span style="color: #DD0000">'create_process_group'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #0000BB">true</span><span style="color: #007700">];<br /></span><span style="color: #0000BB">$proc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">proc_open</span><span style="color: #007700">(</span><span style="color: #0000BB">$cmd</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$descspec</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$pipes</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">null</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$options</span><span style="color: #007700">);<br />while&nbsp;(</span><span style="color: #0000BB">true</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">fgets</span><span style="color: #007700">(</span><span style="color: #0000BB">$pipes</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">]);<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
   </div>

  </div>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.sapi-windows-generate-ctrl-event-seealso">
  <h3 class="title">参见</h3>
  <ul class="simplelist">
   <li class="member"><span class="function"><a href="function.proc-open.html" class="function" rel="rdfs-seeAlso">proc_open()</a> - 执行一个命令，并且打开用来输入/输出的文件指针。</span></li>
   <li class="member"><span class="function"><a href="function.sapi-windows-set-ctrl-handler.html" class="function" rel="rdfs-seeAlso">sapi_windows_set_ctrl_handler()</a> - Set or remove a CTRL event handler</span></li>
  </ul>
 </div>


</div></div></div></body></html>